/* 
外部统一发送请求的函数库

*/
import jsonp from 'jsonp'
import ajax from './ajax'
import {message }from 'antd';

// 登录
export const LoginAPI  = (username,password)=>ajax('/login',{username,password},'POST')
//获取用户信息，用于实现自动登录
export const GetUser = () =>ajax('/search_user')
//
export const getWeather = () =>ajax('/weather')
//获取地理编码，这个请求方式为jsonp
export const getAdress = (url)=>{
    return new Promise((resolve,reject)=>{

        jsonp(url,{timeout:2000,},function(error,data){
            console.log(error,data)
            if(!error){
                message.success("数据请求成功")
                resolve(data)
            }else{
                message.error("数据请求失败")
            }
    })
    })
   
}
//分类管理的三个接口
//获取一级或者二级分类列表
export const reqGetCategoryList = (parentId) =>ajax('/manage/category/list',{parentId})
//添加分类
export const reqAddCategory = ({parentId,categoryName}) =>ajax('/manage/category/add',{parentId,categoryName},'POST')
//更新分类
export const reqUpdate = ({categoryId,categoryName}) =>ajax('/manage/category/update',{categoryId,categoryName},'POST')

//商品管理的接口-----------
//获取商品列表
export const reqProduct = ({pageNum,pageSize})=>ajax('/manage/product/list',{pageNum,pageSize})
//查找商品,可能按照名字或者分类搜索
export const reqSearchProduce = (pageNum,pageSize,searchType,detail)=>ajax('/manage/product/search',
{
    pageNum,
    pageSize,
    [searchType]:detail
})
//修改商品的状态，上架或者下架
export const reqChangeState = (productId,status)=>ajax('/manage/product/updateStatus',{productId,status},'POST')
//根据id查询商品所属的分类
export const reqGetClass = (categoryId )=>ajax('/manage/category/info',{categoryId })
//添加商品的接口
export const reqAddProduct = ({categoryId,pCategoryId ,name,desc,price,detail,imgs})=>ajax('/manage/product/add',{categoryId,pCategoryId ,name,desc,price,detail,imgs},'POST')

//删除图片的接口
export const reqDeletePic = (name)=>ajax('/manage/img/delete',{name},"POST")

//请求角色列表的接口
export const reqRoleList = ()=>ajax('/manage/role/list')
//添加角色
export const reqAddRole = ({roleName})=>ajax('/manage/role/add',{roleName},'POST')
/* |_id          |Y       |string   |角色ID
|menus       |Y       |array    |权限key数组
|auth_time    |Y       |number   |权限时间
|auth_name    |Y       |string   |权限人姓名 */
//更新角色权限
export const reqUpdateRoleRight = (_id,menus,auth_time,auth_name)=>ajax('/manage/role/update',{_id,menus,auth_time,auth_name},'POST')